#include "AnimationData.h"
#include <cmath>

namespace DYGraphics
{
	AnimationFrame* AnimationData::Evaluate(float mTime, bool isLoop)
	{
		if (isLoop) mTime = fmod(mTime, mDuration);

		AnimationFrame* animFrame = new AnimationFrame();
		for (auto iter = mCurveMap.begin(); iter != mCurveMap.end(); iter++)
		{
			std::string boneName = iter->first;
			AnimationBoneCurve* boneCurve = iter->second;

			AnimationBoneFrame boneFrame;
			boneFrame.mBoneName = boneName;
			boneFrame.mRotation = boneCurve->EvaluateRotation(mTime);
			boneFrame.mTranslation = boneCurve->EvaluateTranslate(mTime);
			boneFrame.mScaling = boneCurve->EvaluateScaling(mTime);
			animFrame->mFrames.push_back(boneFrame);
		}

		return animFrame;
	}
}
